
package pieces;
import mainClasses.*;
import java.lang.Math;
public class Knight extends Piece{
	/**
	 * Constructor for the king class which create the Knight object
	 * If the colour is white then it is player 1's piece
	 * If the colour is black then it is player 2's piece
	 * 
	 * @param xaxis - x value of location of this piece
	 * @param yaxis - y value of location of this piece
	 * @param b - It is the board which the piece will be placed in.
	 * @param color - It represent the side of the piece
	 */
	public Knight(int xaxis, int yaxis, Board board, String color)
	{
		super(xaxis, yaxis, board, " Knight  ", color);
		if(color!="White")
		{
			super.type = "BK-Knight";
			
		}
	}
	
	/** 
	 * This method checks if this knight piece can be moved to a given location on the board.
	 * 
     * @param p2 - Destination of this piece on the board
     * @return boolean set to true if this piece can be moved to the location p2 and false if not.
     */
	public boolean movePossible(int desx, int desy)
	{

		if(desx>7||desx<0||desy>7||desy<0)
        {
        	return false;
        }else if(this.board.getPiece(desx, desy).type.equals("         ")||this.isEnemy(desx, desy)) //only can be moved if the destination is an enemy or Nullpiece
		{
			if(Math.abs(x-desx)==2 && Math.abs(y-desy)==1) //if the move is up or down two blocks and right or left one block
			{
				return true; //if it is then the move is possible
			}else if(Math.abs(x-desx)==1 && Math.abs(y-desy)==2) //if the move is right or left two blocks and up or down one block
			{
				return true; //if it is then the move is possible			
			}else  //otherwise the move is not possible
			{
				return false;
			}
		}
		return false;
	}
	
	/**
	 * This method is the same as the move method in piece class
	 * But it uses the knightSwap() method in board class
	 * 
	 * @param p2 - location of the destinaton of this knight on board
	 */
	public void moveKnight(int desx, int desy)
	{
		this.board.knightSwap(this.getX(), this.getY(), desx, desy);
	}
}
